
<div id="items-grid">
	<div><span class="page-heading" style="float:left">Item Description</span><br />
	<?php 
		if ($offer['fb_id'] == $fb_id && $offer['status'] != 'Closed'){
			$json = json_encode($offer);
			echo '<script type="text/javascript">var offer = ' . $json . ';</script>';
			echo '<div id="top-options">';
			echo '<div id = "facebook-button"><a href="JavaScript:void(0);" onclick="shareFB(\''. base_url().'\')"></a></div>';
			echo '<div id = "twitter-button"><a href="https://twitter.com/share?text=I am offering this up for grabs at The Trove!" target="_blank"></a></div>';
			echo '<div class="medium-text"><a href="../offerform/' . $offer['offer_id'] . '">Edit item</a></div>';
			echo '</div>';
		}
		echo '<div style="clear:both"></div>';
		echo '</div>';
		echo '<div id = "currentItem-container">';
		echo '<div class="item-container">';
		echo '<div class="img-container"><img class="resize-200" src="' . base_url('/resources/offer_images_thumbnail/'. $offer['item_pic']) . '" /></div>';
		echo '<div class="cnt-container medium-text">';
		echo '<span style="font-weight: bold">' . $offer['item_title'] . '</span><br />';
		echo 'Age: ' . (($offer['age_year']!=0)?(($offer['age_year']==4)?'>3':$offer['age_year']) . ' year ':'') . (($offer['age_year']!=4)?(($offer['age_month']==0)?'<1':$offer['age_month']) . ' months &nbsp&nbsp&nbsp':'&nbsp&nbsp&nbsp') ;
		echo '<br /><div id=star>Condition: &nbsp&nbsp</div>' ;
		echo '<div id = "star" class = "rate_widget">
				<div class="star_1 ratings_stars"></div>  
				<div class="star_2 ratings_stars"></div>  
				<div class="star_3 ratings_stars"></div>  
				<div class="star_4 ratings_stars"></div>  
				<div class="star_5 ratings_stars"></div>
				</div><br />';
		echo '<input type="hidden" id="item_condition" name="item_condition" value="' . $offer['item_condition'] . '" />' ;

		echo 'Tag: <a href="'.base_url().'browse/'.$offer['category_id'].'">'.$offer['category_name'] . '</a> - ' . $offer['sub_category_name'] . '<br />';
		echo 'Owner: <a href="../profile/' . $offer['fb_id'] . '"><span class="get-fb-name">'. $offer['fb_id'] .'</span></a><br />';
		echo '<span class="medium-text">Status: ' . $offer['status'] . '</a><br />';
		if($offer['item_price'] == '0.00'){
			echo 'Price: Free!<br />';
		}
		else{
			echo 'Price: $' . $offer['item_price'] . '<br />';
		}
		echo '</div>';
		echo '<div id="buttons-container">';
			
			if ($offer['status'] != 'Closed')
			{
				if ($offer['fb_id'] == $fb_id)
					echo '<div id="alternative-button"><a href="'.base_url().'alternatives/'.$offer['category_id'].'"></a></div>';
				else
				{
					if ($requesters)
					{
						if ($requesters[0]['status']=='Pending' || $requesters[0]['status']=='Offered to someone else')
							echo '<div id = "remove-button"><a href="JavaScript:void(0);" onclick ="cancel_pending_offer('. $offer['offer_id'] . ');"></a></div>';
						
						if ($requesters[0]['status']=='Offered to you')
						{
							echo '<div id = "accept-button"><a href="JavaScript:void(0);" onclick ="accept_offer('. $offer['offer_id'] . ');"></a></div>';
							echo '<div id = "cancel-button"><a href="JavaScript:void(0);" onclick ="cancel_accepted_offer('. $offer['offer_id'] . ');"></a></div>';
						}
					}
					else
					{
						echo '<div id = "request-button"><a href="JavaScript:void(0);" onclick ="request_offer('. $offer['offer_id'] . ',\''. $offer['status'].'\');"></a></div>';
					}
				}
			}
			
		echo '</div>';
		echo '<div style="clear: both;"></div>';
		echo '</div>';
		echo '<div id="description" class="medium-text"><br/ >Item description : ' . nl2br($offer['item_desc']) . '<br /></div>';
		echo '</div>';	
		
	?>
</div>

<?php

	if ($offer['fb_id'] == $fb_id){
	echo '<div class="horizontal-bar"></div>';
	echo '<div id="requesters-grid">';
	echo '<span class="page-subheading">Requesters</span><br />';
	echo '<div id="requesters-container">';
		echo '<span class="control" id="leftControl">left</span>';
		echo '<div class="slide-container">';
				$i = 0;
				if(count($requesters) == 0){
					echo '<div class="slide">';
					echo '<br /><span class="medium-text">No requesters for this item yet!</span>';
					echo '</div>';
				}
				
				foreach($requesters as $r){
					if($i % 7 == 0){
						echo '<div class="slide">';
					}
					echo '<div class = "requester"><a href="'.base_url('/profile/' . $r['fb_id']) . '"><span class="get-fb-pic">'.$r['fb_id'].'</span><br />';
					echo '<span class="get-fb-name small-text">'.$r['fb_id'].'</span></a><br />';
					if($offer['status'] == 'Available'){
						echo '<a class="action-button action-give" href="Javascript:void(0)" onclick="give_offer('.$offer['offer_id'].','.$r['fb_id'].')"></a>';
					}
					else if ($offer['status'] == 'Reserved' && $r['status'] == 'Offered to you'){
						echo '<span class="normal-text">Reserved</span>';
						echo '<a class="action-button action-cancel" href="Javascript:void(0)" onclick="reject_requester('.$offer['offer_id'].')"></a>';
					}
					echo '</div>';
					if($i % 7 == 6){
						echo '</div>';
					}
					$i++;
				}
				if($i % 7 != 0){
					echo '</div>';
				}
		echo '</div>';
		echo '<span class="control" id="rightControl">right</span>';
	echo '</div>';
echo '</div>';

	}
	?>

<div class="horizontal-bar"></div>

<div id="comments-grid">
	<span class="page-subheading">Comments</span><?php if ($offer['status'] == 'Reserved' || $offer['status'] == 'Closed'){ echo "<span class='normal-text'> This is a private chat between the owner and the receipent.</span>"; }else{ echo "<span class='normal-text'> This is a public chat.</span>";}?><br />
	<div id="comments-container">
	<?php
		if(sizeof($comments) == 0){
			echo '<div><span class="medium-text">No Comments Found!</span><br /></br /></div>';
		}
		foreach($comments AS $c){
			echo '<div class="single-comment-container" id = "comment_' . $c['chat_id'] . '">';
			echo '<div class="facebook-info">';
			echo '<span class="get-fb-pic">' . $c['poster_fb_id'] . '</span>';
			echo '</div>';
			echo '<div class="comment-content">';
			echo '<div class = "datetime small-text">'.$c['date_created'].'</div>';
			echo '<span class="get-fb-name">'.$c['poster_fb_id'].'</span> says: <br />';
			echo '<div class = "message">'.nl2br($c['message']).'</div>';
			if($c['poster_fb_id'] == $fb_id && $offer['status'] != 'Closed'){
				echo '<br /><a class = "action-button action-delete" href = "Javascript:void(0);" onclick="deleteComment('. $c['chat_id'] . ')" /></a>';
			}
			echo '</div>';
			echo '<div style="clear: both"></div>';
			echo '</div>';
		}
		
		if (count($comments) != 0)
			$lasttimestamp = $comments[count($comments)-1]['date_created'];
		else
			$lasttimestamp = '';
		echo '<script language="javascript">lasttimestamp = \''.$lasttimestamp.'\';</script>';
		
		if (($offer['status'] == 'Available') || //not closed
			(($offer['status'] == 'Reserved' || $offer['status'] == 'Closed') && //reserved
			($offer['fb_id'] == $fb_id || //owner
			($requesters[0]['fb_id'] == $fb_id && ($requesters[0]['status'] == 'Offered to you' || $requesters[0]['status'] == 'Closed')) //current user is the offered person
			))){
			
			echo '<div class="new-comment">';
			echo '<textarea id="comment-field" class="normal-text" placeholder="Enter your comment here."></textarea><br />';
			echo '<a class = "action-button action-submit" href = "Javascript: void(0);" onclick="submitComment('. $offer['offer_id'].','.$fb_id.')" /></a>';
			echo '</div>';
		}
	?>
	</div>	
</div>
<div style="height: 30px"></div>